let model = require('../model/model.js');
let preGrounart={}
preGrounart.getarticle=async (req,res)=>{
    let { page =1,pagesize=3}=req.query

    let limit=(page-1)*pagesize
    let sql='SELECT t1.*,t2.classify from `article mark` t1 LEFT JOIN cate t2 ON t1.classify2=t2.article_id WHERE t1.is_delete=0 and t1.status = 1 limit  '+limit+','+pagesize+''
    let result=await model(sql)
    res.json( { result})
}
preGrounart.catecount= async (req,res)=>{
    let sql =`select * from cate where ishide = 1`
    let result = await model(sql)
    res.json(result)
}
preGrounart.getidArt= async (req,res)=>{
    let { id} =req.query;
    if( Number(id)){
    let sql='SELECT t1.*,t2.classify from `article mark` t1 LEFT JOIN cate t2 ON t1.classify2=t2.article_id WHERE t1.art_id='+id
    let result = await model(sql)
    res.json(result[0])
}else{
    res.json( { message:"404"})
}
   

}
preGrounart.getidcate= async (req,res)=>{
    let { id , page =1,pagesize=3} =req.query;
    // console.log(id)
    let limit=(page-1)*pagesize
    let sql='SELECT t1.*,t2.classify from `article mark` t1 LEFT JOIN cate t2 ON t1.classify2=t2.article_id WHERE t1.status=1  and t1.classify2='+id+' limit  '+limit+','+pagesize+''
    let result = await model(sql)
    // console.log(result)
    res.json(result)
}
module.exports=preGrounart;